import React from 'react'
import {
  Switch,
  Route,
  Redirect,
  Router,
  HashRouter
} from 'react-router-dom';
import { createBrowserHistory } from 'history';
const history = createBrowserHistory();
import loadable from '@react/utils/loadable.jsx'//路由懒加载

//路由文件
import index from '@react/views/index/index.jsx'; //默认首页
const box = loadable(()=>import('@react/views/box/index.jsx')) //路由懒加载写法

class RouterIndex extends React.Component {
  componentDidMount(props) {  //DOM已经渲染后

  };
  render() {
    return ( //switch用于匹配路由path//exact是用于精准匹配，这里是定义了路由重定向，意思是当我们进入"/"时会重定向到“/index”
      <Router history={history}>
        <div>
          <HashRouter>
            {/* HashRouter 添加路由哈希必须包裹所有路由 */}
            <Switch>
              <Route path='/' exact render={() => (
                <Redirect to='/index' />
              )} />
              <Route path='/index' component={index} />
              {/* <Route path='/box' component={box} /> */}
              <Route path='/box/:time?' component={box} />
            </Switch>
          </HashRouter>
        </div>
      </Router>
    )
  }
}
export default RouterIndex 